home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / GRAPHICS / GIF2RPC.SPK / source / c / calc8x8dithe next >
Text File  |  1995-09-17  |  2KB  |  65 lines

  1. /* calc8x8dither.c
  2.  * AUTHOR:      Cy Booker, cy@cheepnis.demon.co.uk
  3.  * LICENSE:     FreeWare, Copyright (c) 1995 Cy Booker, but see below
  4.  * PURPOSE:     convert an 8 bit image to a 16 bit image
  5.  */
  6.  
  7. #include "calc8x8dither.h"
  8.  
  9. #include <assert.h>
  10.  
  11. #include "OS:macros.h"
  12.  
  13. #include "map16bpp.h"
  14.  
  15.  
  16.  
  17. /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  18.  */
  19.  
  20. #define PROCESS(C1, C2)                                                         \
  21.   dist = distance_between_midpoint_16bpp_and_palette_entry(colour, (C1), (C2)); \
  22.   if (dist == 0) {                                                              \
  23.     dither[0] = (C1);                                                           \
  24.     dither[1] = (C2);                                                           \
  25.     return;                                                                     \
  26.   }                                                                             \
  27.   if (dist < min_dist) {                                                        \
  28.     min_dist = dist;                                                            \
  29.     dither[0] = (C1);                                                           \
  30.     dither[1] = (C2);                                                           \
  31.   }
  32.  
  33. extern void calculate_8x8dither(
  34.                 bits            dither[2],
  35.                 os_colour       colour) {
  36.   bits  neighbours[9];          /* entry 8 is the nearest
  37.                                  * entry (n & 1) is red +/-1
  38.                                  * entry (n & 2) is green +/-1
  39.                                  * entry (n & 4) is blue +/-1
  40.                                  */
  41.   bits          closest;
  42.   int           i;
  43.   unsigned int  dist, min_dist;
  44.   int           best[2];
  45.  
  46.   assert(bits);
  47.   neighbours[8] = closest = map_palette_entry_to_16bpp_colour(colour);
  48.   min_dist = ~0u;
  49.   PROCESS(closest, closest);
  50.   for (i= 0; (i < 7); i++) {
  51.     neighbours[i] = map_palette_entry_to_16bpp_colour_offset(colour, i);
  52.     PROCESS(closest, neighbours[i])
  53.   }
  54.   for (i= 0; (i < 7); i++) {
  55.     for (j= i+1; (j < 8); j++) {
  56.       PROCESS(neighbours[i], neighbours[j])
  57.     }
  58.   }
  59.   assert(min_dist != ~0u);
  60.   /*
  61.    * here already set up a closest match
  62.    */
  63.   return;
  64. }
  65.